/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.ranges.DocumentRange;
import org.w3c.dom.ranges.Range;
import org.xml.sax.SAXException;

/**
 *
 * @author NDH
 */
public class StudentRange {

    public static void main(String[] args) {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder loader = factory.newDocumentBuilder();
            Document document = null;
            try {
                document = loader.parse("student.xml");
            } catch (SAXException ex) {
                Logger.getLogger(StudentRange.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(StudentRange.class.getName()).log(Level.SEVERE, null, ex);
            }
            Element root = document.getDocumentElement();
            DocumentRange docRange = (DocumentRange) document;
            Range range = docRange.createRange();
            range.setStartAfter(root.getFirstChild());
            range.setEndBefore(root.getLastChild());
            range.deleteContents();
            range.detach();
            for (Node n = root.getFirstChild(); n!=null; n = n.getNextSibling()) {
                System.out.println(""+n.getNodeName()+" text is "+n.getTextContent());
            }
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(StudentRange.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
